package mahan.data.model;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.mongodb.DBObject;

public class Customer implements KeyValuePair {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static Customer from(DBObject dbo) {
		Map map = dbo.toMap();
		int id = (Integer) map.get("id");
		Date c = (Date) map.get("created");
		Customer cust = new Customer(id, c);
		cust.put(map);
		return cust;
	}

	public static Customer instance() {
		return new Customer();
	}

	private int id;
	private String firstName;
	private String lastName;
	private String facebookID;

	private String twitterID;
	private String address;
	private String city;
	private String state;
	private String country;
	private String zip;
	private String emailAddress;

	private String phoneNumber;

	private Date createdOn;
	private Date lastVisit;

	private Date lastPurchase;

	private boolean admin = false;

	private Customer() {
	}

	public Customer(int id, Date c) {
		this.id = id;
		this.createdOn = c;
	}

	public Map<String, ?> get() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("fn", firstName);
		map.put("ln", lastName);
		map.put("fbk", facebookID);
		map.put("twit", twitterID);
		map.put("address", address);
		map.put("city", city);
		map.put("state", state);
		map.put("country", country);
		map.put("zip", zip);
		map.put("email", emailAddress);
		map.put("phone", phoneNumber);
		map.put("created", createdOn);
		map.put("lastv", lastVisit);
		map.put("lastp", lastPurchase);
		map.put("admin", admin);

		return map;
	}

	public String getAddress() {
		return address;
	}

	public String getCity() {
		return city;
	}

	public String getCountry() {
		return country;
	}

	public Date getCreatedOn() {
		return createdOn;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public String getFacebookID() {
		return facebookID;
	}

	public String getFirstName() {
		return firstName;
	}

	public int getId() {
		return id;
	}

	public String getLastName() {
		return lastName;
	}

	public Date getLastPurchase() {
		return lastPurchase;
	}

	public Date getLastVisit() {
		return lastVisit;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public String getState() {
		return state;
	}

	public String getTwitterID() {
		return twitterID;
	}

	public boolean isAdmin() {
		return admin;
	}

	public void put(Map<String, ?> map) {
		id = (Integer) map.get("id");
		firstName = (String) map.get("fn");
		lastName = (String) map.get("ln");
		facebookID = (String) map.get("fbk");
		twitterID = (String) map.get("twit");
		address = (String) map.get("address");
		city = (String) map.get("city");
		state = (String) map.get("state");
		country = (String) map.get("country");
		zip = (String) map.get("zip");
		emailAddress = (String) map.get("email");
		phoneNumber = (String) map.get("phone");
		createdOn = (Date) map.get("created");
		lastVisit = (Date) map.get("lastv");
		lastPurchase = (Date) map.get("lastp");
		admin = (Boolean) map.get("admin");
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setAdmin(boolean admin) {
		this.admin = admin;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public void setFacebookID(String facebookID) {
		this.facebookID = facebookID;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public void setLastPurchase(Date lastPurchase) {
		this.lastPurchase = lastPurchase;
	}

	public void setLastVisit(Date lastVisit) {
		this.lastVisit = lastVisit;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setTwitterID(String twitterID) {
		this.twitterID = twitterID;
	}
}